/*
 * tilesetImageLayer.cpp
 *
 *  Created on: Aug 9, 2013
 *      Author: jason
 */

#include <tinyxml.h>
#include "../../include/Tileset/tilesetImageLayer.hpp"
#include "../../include/Tileset/tilesetImage.hpp"

namespace Tmx
{
  ImageLayer::ImageLayer(const Map *map, int _depth = 0)
  {
	  height = 0;
	  width = 0;
	  visible = 1;
	  pMap = map;
	  opacity = 0;
	  image = NULL;
	  depth = 0;
  }

  ImageLayer::~ImageLayer()
  {
	  if (image) {
		  delete image;
	  }
  }

  void ImageLayer::parse(TiXmlNode *imageLayerNode)
  {
	  const TiXmlElement *imageLayerElement = imageLayerNode->ToElement();
	  name = imageLayerElement->Attribute("name");
	  imageLayerElement->Attribute("height", &height);
	  imageLayerElement->Attribute("width", &width);
	  const char *opac = imageLayerElement->Attribute("opacity");
	  if (opac) {
		  opacity = (float)atof(opac);
	  }
	  const char *vis= imageLayerElement->Attribute("visibility");
	  if (vis) {
		  if (vis == "0")
			  visible = 0;
	  }
	  const TiXmlNode *imageNode = imageLayerElement->FirstChild("image");
	  if (imageNode) {
		  image = new Image();
		  image->parse(imageNode);
	  }
	  //TiXmlNode *propertiesNode = imageLayerElement->FirstChild("properties");
	  //if (properties) {
		  // Do Nothing.
		  // Will implement if I decide to use this.
	  //}
  }
}; // namespace Tmx
